package com.museum.guide.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.museum.guide.common.result.Result;
import com.museum.guide.entity.Collections;
import com.museum.guide.service.CollectionsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/collections")
public class CollectionsController {

    @Resource
    private CollectionsService collectionsService;

    /**
     * 分页查询藏品信息
     */
    @GetMapping("/page")
    public Result<Page<Collections>> page(Page<Collections> page, String name, Long categoryId) {
        return Result.success(collectionsService.page(page, name, categoryId));
    }

    /**
     * 新增藏品
     */
    @PostMapping("/add")
    public Result<Void> save(@RequestBody @Valid Collections collections) {
        collectionsService.saveCollections(collections);
        return Result.success();
    }

    /**
     * 更新藏品信息
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody @Valid Collections collections) {
        collectionsService.updateCollections(collections);
        return Result.success();
    }

    /**
     * 删除藏品
     */
    @DeleteMapping("/removeById")
    public Result<Void> remove(Long id) {
        collectionsService.removeCollections(id);
        return Result.success();
    }

    /**
     * 获取精选藏品
     */
    @GetMapping("/featured")
    public Result<List<Collections>> getFeaturedCollections() {
        LambdaQueryWrapper<Collections> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Collections::getFeatured, 1);
        return Result.success(collectionsService.list(queryWrapper));
    }
}